package xyz.bali16.module.article.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Preconditions;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import xyz.bali16.module.article.entity.Tag;
import xyz.bali16.module.article.mapper.TagMapper;
import xyz.bali16.module.article.model.tag.TagAddParam;
import xyz.bali16.module.article.model.tag.TagPageParam;
import xyz.bali16.module.article.model.tag.TagUpdateParam;
import xyz.bali16.module.article.service.TagService;

import java.util.List;

@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements TagService {

    @Override
    public IPage<Tag> getPage(TagPageParam param) {
        IPage<?> page = new Page<>(param.getCurrent(), param.getSize());
        return this.baseMapper.getTagPage(page, param.getName(),param.getUrl());
    }

    @Override
    public void addTag(TagAddParam param) throws Exception {
        Preconditions.checkNotNull(param, "TagAddParam 参数不能为为空");
        Tag tag = new Tag();
        BeanUtils.copyProperties(param, tag);
        System.out.println(tag);
        save(tag);
    }

    @Override
    public void updateTag(TagUpdateParam param) throws Exception {
        Preconditions.checkNotNull(param, "TagUpdateParam 参数不能为为空");
        Tag tag = new Tag();
        BeanUtils.copyProperties(param, tag);
        updateById(tag);
    }

    @Override
    public void delete(String tagId) throws Exception {
        if (tagId == null) {
            return;
        }
        removeById(tagId);
    }
}



